package com.ruoyi.web.controller.play;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.play.domain.PlayAll;
import com.ruoyi.play.service.IPlayAllService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 短剧片单Controller
 *
 * @author ruoyi
 * @date 2025-11-20
 */
@RestController
@RequestMapping("/play/all")
public class PlayAllController extends BaseController {
    @Autowired
    private IPlayAllService playAllService;

    /**
     * 查询短剧片单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PlayAll playAll) {
        startPage();
        List<PlayAll> list = playAllService.selectPlayAllList(playAll);
        return getDataTable(list);
    }

    @GetMapping("/all")
    public AjaxResult all(PlayAll playAll) {
        return success(playAllService.selectPlayAllList(playAll));
    }

    /**
     * 导出短剧片单列表
     */
    @Log(title = "短剧片单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlayAll playAll) {
        List<PlayAll> list = playAllService.selectPlayAllList(playAll);
        ExcelUtil<PlayAll> util = new ExcelUtil<PlayAll>(PlayAll.class);
        util.exportExcel(response, list, "短剧片单数据");
    }

    /**
     * 获取短剧片单详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(playAllService.selectPlayAllById(id));
    }

    /**
     * 新增短剧片单
     */
    @Log(title = "短剧片单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlayAll playAll) {
        return toAjax(playAllService.insertPlayAll(playAll));
    }

    /**
     * 修改短剧片单
     */
    @Log(title = "短剧片单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlayAll playAll) {
        return playAllService.updatePlayAll(playAll);
    }

    /**
     * 删除短剧片单
     */
    @Log(title = "短剧片单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(playAllService.deletePlayAllByIds(ids));
    }
}
